package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    TbClueMapper tbClueMapper;
//添加跟进线索
    @Override
//    差一个修改状态
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        String username = SecurityUtils.getUsername();
        Date date = new Date();
        ClueTrackRecordVo tbClue=new ClueTrackRecordVo();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setCreateTime(date);
        tbClue.setCreateBy(username);
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());

//        根据前端传过来的数据  更新原来的线索表  增加新的线索跟进表
//        根据线索id更新当前的线索表
        tbClueMapper.updateTbClueById(tbClue);
        TbClueTrackRecord trackRecord=new TbClueTrackRecord();
//        在跟进记录表添加数据  （判断数据是否吻合）




        tbClueTrackRecordMapper.addClueTrackRecord(tbClue);







    }
//展示跟进线索
    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
//        根据线索id联合查询线索和线索跟进表

       List<TbClueTrackRecord> trackRecordList=tbClueTrackRecordMapper.listClueTrackRecord(clueId);

        return trackRecordList;
    }
}
